package top.hkyzf.study.leetcode.array;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * description: 
 * @author zhufeng
 * @date 2024/1/24 0024 18:33
 * @version V1.0
 */
public class 美丽塔_I_2865 {
    public long maximumSumOfHeights(List<Integer> maxHeights) {
        long max = 0;
        for (int i = 0; i < maxHeights.size(); i++) {
            max = Math.max(max, calcSum(i, maxHeights));
        }
        return max;
    }

    private long calcSum(int i, List<Integer> maxHeights) {
        int[] heights = new int[maxHeights.size()];
        heights[i] = maxHeights.get(i);
        for (int j = i; j > 0; j--) {
            Integer cur = heights[j];
            Integer prev = maxHeights.get(j - 1);
            if (prev <= cur) {
                heights[j-1] = prev;
            } else {
                heights[j-1] = cur;
            }
        }
        for (int j = i; j < maxHeights.size()-1; j++) {
            Integer cur = heights[j];
            Integer next = maxHeights.get(j + 1);
            if (next <= cur) {
                heights[j+1] = next;
            } else {
                heights[j+1] = cur;
            }
        }
        long max = 0;
        for (int height : heights) {
            max = max + height;
        }
        return max;
    }

    @Test
    public void testMaximumHeights () {
        List<Integer> maxHeights = Arrays.asList(3,2,5,5,2,3);
        long max = maximumSumOfHeights(maxHeights);
        System.out.println(max);
    }
}
